home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / App / Sources / UPerform.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  6.1 KB  |  221 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UPerform.cp
  3. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UPERFORM__
  7. #include "UPerform.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UDIALOG__
  13. #include "UDialog.h"
  14. #endif
  15.  
  16. #ifndef __UFILE__
  17. #include "UFile.h"
  18. #endif
  19.  
  20. #ifndef __UCOREGLOBALS__
  21. #include "UCoreGlobals.h"
  22. #endif
  23.  
  24. #ifndef __UCOREUTILITIES__
  25. #include "UCoreUtilities.h"
  26. #endif
  27.  
  28. #ifndef __UMEMORY__
  29. #include "UMemory.h"
  30. #endif
  31.  
  32. //    #ifndef __USEGMENTS__
  33. //    #include "USegments.h"
  34. //    #endif
  35.  
  36. #ifndef __UWINDOW__
  37. #include "UWindow.h"
  38. #endif
  39.  
  40. // Toolbox
  41.  
  42. // ANSI
  43.  
  44. #ifndef __STDIO__
  45. #include <stdio.h>
  46. #endif
  47.  
  48. // Apple Specials
  49.     
  50. #if qPerform
  51.     #ifndef __PERF__
  52.     #include "Perf.h"
  53.     #endif
  54. #endif
  55.  
  56. //----------------------------------------------------------------------------------------
  57. // Static variable definitions.
  58. //----------------------------------------------------------------------------------------
  59.  
  60. #if qPerform
  61.  
  62. static TP2PerfGlobals pTP2PerfGlobals;            // Pointer to performance globals record
  63.                                                 // Non-NULL if tools are inited
  64.  
  65. static Boolean pPerfMonitorEnabled;                // Is the performance monitor enabled or
  66.                                                 // disabled.
  67. #endif
  68.  
  69. //========================================================================================
  70. // GLOBAL Procedures
  71. //========================================================================================
  72. #undef Inherited
  73.  
  74. #if qPerform
  75.  
  76. //----------------------------------------------------------------------------------------
  77. // PerfMonitorInitiated: Are we currently doing performance monitoring.
  78. //----------------------------------------------------------------------------------------
  79. #pragma segment MADebugger
  80.  
  81. Boolean PerfMonitorInitiated()
  82. {
  83.     return pTP2PerfGlobals != NULL;
  84. } // PerfMonitorInitiated
  85.  
  86.  
  87. //----------------------------------------------------------------------------------------
  88. // InitiatePerfMonitor: Initiate performance monitoring from the initialize performance
  89. // monitor dialog box.
  90. //----------------------------------------------------------------------------------------
  91. #pragma segment MADebugger
  92.  
  93. void InitiatePerfMonitor(TWindow* aWindow)
  94. {
  95. #if !qPowerPC
  96.     Boolean aBool;
  97.     
  98.     short timerCount = (short) ((TNumberText *) aWindow->FindSubView('tmct'))->GetValue();
  99.     short codeAndROMBucketSize = (short) ((TNumberText *) aWindow->FindSubView('cbsz'))->GetValue();
  100.     Boolean doROM = ((TCheckBox *) aWindow->FindSubView('mrcd'))->IsOn();
  101.     Boolean doAppCode = ((TCheckBox *) aWindow->FindSubView('macd'))->IsOn();
  102.     CStr255 appCodeType;
  103.     ((TEditText *) aWindow->FindSubView('acrs'))->GetText(appCodeType);
  104.     short romID = (short) ((TNumberText *) aWindow->FindSubView('rmid'))->GetValue();
  105.     CStr255 romName;
  106.     ((TEditText *) aWindow->FindSubView('rmnm'))->GetText(romName);
  107.     Boolean doRAM = ((TCheckBox *) aWindow->FindSubView('mout'))->IsOn();
  108.     long ramLow = ((TNumberText *) aWindow->FindSubView('from'))->GetValue();
  109.     long ramHigh = ((TNumberText *) aWindow->FindSubView('to  '))->GetValue();
  110.     short ramBucketSize = (short) ((TNumberText *) aWindow->FindSubView('otsz'))->GetValue();
  111.         
  112.     aBool = InitPerf(&pTP2PerfGlobals, timerCount, codeAndROMBucketSize, doROM, doAppCode,
  113.                      appCodeType, romID, romName, doRAM, ramLow, ramHigh, ramBucketSize);
  114.     
  115.     if (!aBool)
  116.         pTP2PerfGlobals = NULL;
  117.     else
  118.         EnablePerfMonitor(TRUE);
  119. #else
  120.     pTP2PerfGlobals = NULL;
  121. #endif
  122. } // InitiatePerfMonitor
  123.  
  124.  
  125. //----------------------------------------------------------------------------------------
  126. // DumpPerfMonitor:
  127. //----------------------------------------------------------------------------------------
  128. void DumpPerfMonitor(const FSSpec& fileSpec)
  129. {
  130. #if !qPowerPC
  131.     if (pTP2PerfGlobals)
  132.     {
  133.         CStr255 pathName;
  134.         
  135.         // Create a TFile to get the pathname.
  136.         
  137.         TFile* aFile = new TFile;
  138.         aFile->IFile('TEXT', 'MPS ', kUsesDataFork, noResourceFork, kDataOpen, !kRsrcOpen);
  139.         aFile->Specify(fileSpec);
  140.         aFile->GetPathName(pathName);
  141.  
  142.         PerfDump(pTP2PerfGlobals, pathName + (const CStr255&) fileSpec.name, TRUE, 80);
  143.         
  144.         delete aFile;
  145.     }
  146. #endif
  147. } // DumpPerfMonitor
  148.  
  149.  
  150. //----------------------------------------------------------------------------------------
  151. // EnablePerfMonitor: Enable or disable performance monitoring, assuming already its
  152. // initiated.
  153. //----------------------------------------------------------------------------------------
  154. #pragma segment MADebugger
  155.  
  156. void EnablePerfMonitor(const Boolean enable)
  157. {
  158. #if !qPowerPC
  159.     if (pTP2PerfGlobals && enable != pPerfMonitorEnabled)
  160.     {
  161.         PerfControl(pTP2PerfGlobals, enable);
  162.         pPerfMonitorEnabled = enable;
  163.     }
  164. #endif
  165. } // EnablePerfMonitor
  166.  
  167.  
  168. //----------------------------------------------------------------------------------------
  169. // PerfMonitorEnabled: Is the performance monitor enabled?
  170. //----------------------------------------------------------------------------------------
  171. #pragma segment MADebugger
  172.  
  173. Boolean PerfMonitorEnabled()
  174. {
  175.     return pPerfMonitorEnabled;
  176. } // PerfMonitorEnabled
  177.  
  178.  
  179. //----------------------------------------------------------------------------------------
  180. // TerminatePerfMonitor: Shut down the performance monitoring tools.
  181. //----------------------------------------------------------------------------------------
  182. #pragma segment MADebugger
  183.  
  184. void TerminatePerfMonitor()
  185. {
  186. #if !qPowerPC
  187.     if (pTP2PerfGlobals)
  188.     {
  189.         TermPerf(pTP2PerfGlobals);
  190.         pTP2PerfGlobals = NULL;
  191.     }
  192. #else
  193.     pTP2PerfGlobals = NULL;
  194. #endif
  195. } // TerminatePerfMonitor
  196.  
  197. #endif    // qPerform
  198.  
  199. //----------------------------------------------------------------------------------------
  200. // DebugTerminate:
  201. //----------------------------------------------------------------------------------------
  202. #pragma segment MADebugger
  203.  
  204. #if qDebug
  205.  
  206. void DebugTerminate()
  207. {
  208. #if qPerform
  209.     // Make sure the performance tools are shut down if they are initialized 
  210.     if (pTP2PerfGlobals)
  211.         TerminatePerfMonitor();
  212. #endif
  213. } // DebugTerminate
  214.  
  215. #endif    // qDebug
  216.  
  217. //----------------------------------------------------------------------------------------
  218. // End of UPerform.cp
  219.  
  220. #pragma segment Inline
  221.